package edu.gdpu.bytecode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author mazebin
 * @date 2021年 07月09日 15:39:02
 * 类型擦除
 */
public class GenericTypeTest1 {
    public static void main(String[] args) {
        List<Integer> integers = new ArrayList<Integer>();
        List<String> strings = new ArrayList<String>();
        System.out.println(strings.getClass());
        System.out.println(integers.getClass() == strings.getClass());
        /**
         * 输出结果为true,
         * 说明类型确实被擦除了
         *   Code:
         *       stack=3, locals=3, args_size=1
         *          0: new           #2                  // class java/util/ArrayList
         *          3: dup
         *          4: invokespecial #3                  // Method java/util/ArrayList."<init>":()V
         *          7: astore_1
         *          8: new           #2                  // class java/util/ArrayList
         *         11: dup
         *         12: invokespecial #3                  // Method java/util/ArrayList."<init>":()V
         *         15: astore_2
         *         16: getstatic     #4                  // Field java/lang/System.out:Ljava/io/PrintStream;
         *         19: aload_1
         *         20: invokevirtual #5                  // Method java/lang/Object.getClass:()Ljava/lang/Class;
         *         23: aload_2
         *         24: invokevirtual #5                  // Method java/lang/Object.getClass:()Ljava/lang/Class;
         *         27: if_acmpne     34
         *         30: iconst_1
         *         31: goto          35
         *         34: iconst_0
         *         35: invokevirtual #6                  // Method java/io/PrintStream.println:(Z)V
         *         38: return
         *       LineNumberTable:
         *         line 15: 0
         *         line 16: 8
         *         line 17: 16
         *         line 22: 38
         *       LocalVariableTable:
         *         Start  Length  Slot  Name   Signature
         *             0      39     0  args   [Ljava/lang/String;
         *             8      31     1 integers   Ljava/util/List;
         *            16      23     2 strings   Ljava/util/List;
         *       擦除法仅仅堆方法code属性中的字节码进行擦除，元数据还保留了原信息，这也是我们能够通过反射取得参数化类型的依据
         */
    }
}
